package com.reliable.service.serviceimpl;

import com.reliable.api.param.user.NotificationConfigUpStatusParam;
import com.reliable.api.param.user.NotificationConfigUpdateParam;
import com.reliable.common.core.domain.AjaxResult;
import com.reliable.service.domain.ReliableUserNotificationConfig;
import com.reliable.service.mapper.ReliableUserNotificationConfigMapper;
import com.reliable.service.service.IReliableUserNotificationConfigService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 用户推送配置Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-07-09
 */
@Service
public class ReliableUserNotificationConfigServiceImpl extends ServiceImpl<ReliableUserNotificationConfigMapper, ReliableUserNotificationConfig> implements IReliableUserNotificationConfigService {


    @Override
    public AjaxResult updateNotificationConfig(NotificationConfigUpdateParam param) {
        Long id = param.getId();
        ReliableUserNotificationConfig xssUserNotificationConfig = baseMapper.selectById(id);
        if (xssUserNotificationConfig == null)
        {
            return AjaxResult.warn("用户推送配置不存在");
        }
        xssUserNotificationConfig.setNotifyType(param.getNotifyType());
        xssUserNotificationConfig.setNotifyName(param.getNotifyName());
        xssUserNotificationConfig.setConfigKey(param.getConfigKey());
        boolean result = baseMapper.updateById(xssUserNotificationConfig) > 0;
        return result ? AjaxResult.success() : AjaxResult.error();

    }

    @Override
    public AjaxResult updateStatus(NotificationConfigUpStatusParam param) {
        Long id = param.getId();
        Integer isActive = param.getIsActive();

        ReliableUserNotificationConfig xssUserNotificationConfig = baseMapper.selectById(id);
        if (xssUserNotificationConfig==null)
        {
            return AjaxResult.error("未找到该记录");
        }

        if (isActive == null){
            return AjaxResult.warn("请选择启用状态");
        }
        xssUserNotificationConfig.setIsActive(isActive);
        boolean update = baseMapper.updateById(xssUserNotificationConfig) > 0;
        return update ? AjaxResult.success() : AjaxResult.error();

    }
}
